Ext.define('qjtravel.view.CompanyInfor', {
    extend: 'Ext.Panel',
    xtype: 'companyInfor',
    requires: [
        'Ext.List', 'Ext.TitleBar',
        'Ext.form.Panel',
        'Ext.Label',
        'Ext.form.FieldSet'
    ],
    config: {
        layout: {
            type: 'vbox',
            align: 'stretch'
        },
        items: [
            {
                xtype: 'titlebar',
                id: 'titlebar',
                ui: 'dark',
                docked: 'top',
                items: {
                    xtype: 'button',
                    text: '返回',
                    listeners: {
                        tap: function () {
                            Ext.Viewport.remove(this.up('companyInfor'), true);

                        }
                    }
                }
            },
            {
                xtype: 'formpanel',
                scrollable: true,
                style: 'margin:10px;backround:#fff',
                height: 0,
                flex: 2,
                items: [
                    {
                        style: 'margin:0 10px;',
                        cls: 'content',
                        html: '',
                        listeners: {
                            initialize: function () {
                                Ext.Viewport.mask({xtype: 'loadmask' });
                                Ext.Ajax.request({
                                    url: Global.api_url + '/cloud/1/product_info_get',
                                    params: {cpid: '67'},
                                    scope: this,
                                    success: function (response) {
                                        Ext.Viewport.unmask();
                                        var result = Ext.decode(response.responseText);
                                        data = result.Variables.data;
                                        var length = data.photos.length;
                                        var image = '';
                                        var imageURL;
                                        //添加图片
                                        for (var i = 0; i < length; i++) {
                                            imageURL = data.photos[i].url;
                                            console.log(data.photos[i].name)
                                            image += '<img src=' + data.photos[i].url + ' width="96%" style="margin:0 10px" />'
                                        }
                                        Ext.getCmp('titlebar').setTitle('机构信息');
                                        data.tel == ' ' ? Ext.getCmp('tel2').hide() : Ext.getCmp('tel2').setHtml('<div style="float: left;margin-right: 10px;"><img src="resources/images/tel2.png" height="20px" style=" vertical-align: middle"/></div>'
                                            + data.tel);
                                        data.address == ' ' ? Ext.getCmp('address2').hide() : Ext.getCmp('address2').setHtml('<div style="float: left;margin-right: 10px;"><img src="resources/images/postion.png" height="20px" style=" vertical-align: middle"/></div>'
                                            + data.address);
                                        if (data.address == ' ' && data.tel == ' ') {
                                            Ext.getCmp('fieldset2').hide()
                                        }else{
                                            Ext.getCmp('callNumber').setValue( data.tel);
                                        }
                                        this.setHtml(data.explain)
                                    },
                                    failure: function () {
                                        Ext.Viewport.unmask();
                                        cordova.exec(function (message) {
                                        }, function (error) {
                                        }, "Messages", "showMsg", ['请求失败', '服务器维护中....']);
                                        return false;

                                    }
                                })
                            }
                        }
                    }, {
                        xtype: 'textfield',
                        id: 'callNumber',
                        hidden: true
                    },
                    {
                        xtype: 'fieldset',
                        id: 'fieldset2',
                        items: [
                            {
                                html: '',
                                cls: 'font1 color1 more_form more_border',
                                id: 'tel2',
                                listeners: {
                                    painted: function (label) {
                                        label.on('tap', function () {
                                            var args = Ext.getCmp('callNumber').getValue();
                                            cordova.exec(function (successCallback) {
                                            }, function (errorCallback) {
                                            }, "Redirect", "callNumber", [args]);
                                            return false;
                                        }, this)
                                    }
                                }
                            },
                            {
                                html: '',
                                cls: 'font1 color1 more_form',
                                id: 'address2',
                                listeners: {
                                    painted: function (label) {
                                        label.on('tap', function () {
                                            var popmap = Ext.create('qjtravel.view.PopMap')
                                            Ext.Viewport.animateActiveItem(popmap, {type: 'slide', direction: 'left'});
                                            var address = Ext.getCmp('address2').getHtml()
                                            popmap.search('西安杜陵邑南路');
                                            return false;
                                        }, this)
                                    }
                                }
                            }
                        ]
                    }
                ]
            }
        ], listeners: {
            back: function () {
                Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
            }
        }
    }
});
